//
//  WQMyMainViewController.m
//  WisdomQuestor
//
//  Created by 纪景城 on 2024/12/19.
//

#import "WQMyMainViewController.h"
#import "WQMyUserInfoCell.h"
#import "WQMyMoreTableCell.h"

@interface WQMyMainViewController ()

@property (nonatomic, strong) UIImageView           *backColorImageView;
@property (nonatomic, strong) UIImageView           *logoImageView;

@property (nonatomic, strong) UIButton           *rightMicrButton; // 麦克风
@property (nonatomic, strong) UIButton           *rightAddButton; // +

@end

@implementation WQMyMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeAll;
    self.hbd_barTintColor = UIColor.clearColor;
    self.hbd_barAlpha = 0;
    
    self.view.backgroundColor = k_Color_ViewDefault;
    
    self.navigationItem.rightBarButtonItems = @[[[UIBarButtonItem alloc] initWithCustomView:self.rightAddButton], [[UIBarButtonItem alloc] initWithCustomView:self.rightMicrButton]];
    
    [self.view addSubviews:[NSArray arrayWithObjects:self.backColorImageView, self.logoImageView, nil]];
    [self.view insertSubview:self.logoImageView atIndex:0];
    [self.view insertSubview:self.backColorImageView atIndex:0];
    
    [self fragmentUI_ViewSet];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tableEndRefresh) name:kNotificationUserInfoUpdate object:nil];
}

#pragma mark ------- Http Mehods -------

- (void)requestHandlerWishIsRefresh:(BOOL)isRefresh {
    [self tableEndRefresh];
}

#pragma mark ------- UITableViewDelegate -------

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return kFragmemtFloat(223);
    } else {
        return kFragmemtFloat(60) * 4;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        
        WQMyUserInfoCell *cell = [WQMyUserInfoCell ff_CellDequeueWithId:tableView];
        
        if (WQShare.isLogin) {
            cell.userNameLabel.text = [ThingSmartUser sharedInstance].userName;
        } else {
            cell.userNameLabel.text = @"请点击登录";
        }
        
        if (WQShare.isVisitorsLogin == YES) {
            cell.userNameLabel.text = @"游客登录";
        }
        
        return cell;
        
    } else {
        WQMyMoreTableCell *cell = [WQMyMoreTableCell ff_CellDequeueWithId:tableView];
        
        
        return cell;
    }
}

#pragma mark ------- Lazy Methods -------

- (void)fragmentUI_ViewSet {
    [self.backColorImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.view);
        make.height.mas_equalTo(kFragmemtFloat(288));
    }];
    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-kFragmemtFloat(28));
        make.size.mas_equalTo(kSizzleKapadate(60, 20));
    }];
}

- (UIImageView *)backColorImageView {
    if (!_backColorImageView) {
        _backColorImageView = [[UIImageView alloc] initWithImage:kImageName(@"me_bg")];
        _backColorImageView.contentMode = UIViewContentModeScaleAspectFill;
        _backColorImageView.userInteractionEnabled = YES;
    }
    return _backColorImageView;
}

- (UIButton *)rightMicrButton {
    if (!_rightMicrButton) {
        _rightMicrButton = [UIButton initWithImage:kImageName(@"me_nav_scan") selectedImage:nil];
    }
    return _rightMicrButton;
}

- (UIButton *)rightAddButton {
    if (!_rightAddButton) {
        _rightAddButton = [UIButton initWithImage:kImageName(@"me_nav_setting") selectedImage:nil];
    }
    return _rightAddButton;
}

- (UIImageView *)logoImageView {
    if (!_logoImageView) {
        _logoImageView = [[UIImageView alloc] initWithImage:kImageName(@"base_logo_my")];
    }
    return _logoImageView;
}

@end
